<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="mall.demo.mybatis.pojo.ProductInCart"%>
<%@ page import="mall.demo.mybatis.pojo.OrderWithDetail"%>
<%@ page import="mall.demo.mybatis.pojo.OrderDetail"%>
<%@ page import="mall.demo.util.SessionKeyEnum"%>
<%@ page import="mall.demo.mybatis.pojo.User"%>
<%@ page import="mall.demo.mybatis.service.OrderService"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.ArrayList"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'order.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<link rel="stylesheet" type="text/css" href="css/order.css">
<style type="text/css">

</style>
</head>
<%
	//首先是获取用户信息，以及获取所有与用户相关的订单信息
	Object obj = session.getAttribute(SessionKeyEnum.userObj.name());
	boolean isUserLoggedIn = false;
	if (obj != null) {
		isUserLoggedIn = true;
	}
	User user = null;
	if (isUserLoggedIn) {
		user = (User) obj;
	}
	int userId = 0;
	//根据用户id（userid）获取订单信息（大概的订单信息）
	if (user != null) {
		userId = user.getUserId();
	}
	List<OrderWithDetail> orderList = (new OrderService())
			.getOdersByUserId(userId);
%>
<body>
	<div class="container">
		<div class="top">
			<div class="top_logo">
				<font id="Logo"><%=user.getNickname() %>的订单</font>
			</div>
			<!-- 分为登录和未登录两种情况 -->
			<div class="top_userInfo">
				<%
					if (isUserLoggedIn) {
				%>
				<b><a href="#">返回首页</a></b> <b><a href="order.jsp">我的订单</a></b> <b><a
					href="logout.do">退出登录</a></b>
				<%
					} else {
				%>
				<b><a href="register.jsp">注册</a></b> <b><a href="login.jsp">登录</a></b>
				<%
					}
				%>
			</div>
			<br>
			<hr>
		</div>

		<div class="order_list_show">
				<%
					if (orderList.size() == 0) {
				%>
				<h3>您还没有订单哦....</h3>
				<%
					} else {
						for (OrderWithDetail orderWD : orderList) {
				%>
				<table>
				<tr>
					<th colspan="3" class="order_top">
						订单号:<%=orderWD.getOrder().getCode()%>&nbsp;&nbsp;&nbsp;&nbsp;
						订单状态:<%=orderWD.getOrder().getStatus() %><br>
						<!-- <font>最后更新时间:<%=orderWD.getOrder().getLastTime() %></font> -->
					</th>
					<th colspan="2" class="order_top">实付款:￥<%=orderWD.getOrder().getTotalPrice() %>元</th>
				</tr>
				<tr>
					<td class="order_detail_info">宝贝</td>
					<td class="order_detail_info">数量</td>
					<td class="order_detail_info">单价</td>
					<td class="order_detail_info">金额</td>
					<td class="order_detail_info">订单操作</td>
				</tr>

				<%
					List<OrderDetail> details = orderWD.getDetails();
							for (OrderDetail detail : details) {
				%>
				<tr>
					<td class="order_detail_content"><%=detail.getProductId()%></td>
					<td class="order_detail_content"><%=detail.getAmount()%></td>
					<td class="order_detail_content"><%=detail.getOrderPrice()%></td>
					<td class="order_detail_content"><b>￥</b><%=detail.getAmount() * detail.getOrderPrice()%></td>
				
				<%
					}
				%>
					<td class="order_detail_content"><a href="DeleteOrderServlet?orderId=<%=orderWD.getOrder().getOrderId() %>">删除订单</a></td>
				</tr>
				</table>
				<br>
				<%
					}
					}
				 %>
			
		</div>
	</div>
</body>
</html>
